home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / lpDaemon SRC / lpr Sources / lprMain.C < prev   
Encoding:
C/C++ Source or Header  |  1993-02-14  |  4.5 KB  |  236 lines  |  [TEXT/KAHL]

  1. /* Main of the new trial run */
  2.  
  3. #include "LPR.H"
  4. #include "TCPStream.H"
  5. #include "BackGrounder.H"
  6. #include "lprProtos.H"
  7.  
  8.  
  9. void DoWindowActivate(WindowPtr window, Boolean activ);
  10. void DoWindowUpdate(WindowPtr window);
  11. void DoWindowClick(WindowPtr window, EventPtr event);
  12. void DoWindowGrow(WindowPtr window, Point mouse);
  13. void DoWindowZoom(WindowPtr window, Boolean in);
  14. void DoWindowKey(WindowPtr window, EventPtr event);
  15. LongWord GetSleep(void);
  16. void DoIdles(integer *state);
  17.  
  18. void main()
  19. {
  20.     Initialise();
  21.     UnloadSeg(Initialise);
  22.  
  23.     SetCursor(&arrow);
  24.  
  25.     haveWaitEvnt = FALSE;
  26.  
  27.     while (TRUE)
  28.         MainEvents(everyEvent);
  29. }
  30.  
  31.  
  32.  
  33. void WaitForEvent(integer evtMask, EventPtr event)
  34. {
  35.     Boolean    gotEvent;
  36.  
  37.     do    {
  38.         CursorAdjust(event->where, cursRgn);               /* update cursor    */
  39.  
  40.         if (haveWaitEvnt)
  41.             gotEvent = WaitNextEvent(evtMask, event, GetSleep(), cursRgn);
  42.         else
  43.             {
  44.             SystemTask();                                 /* run drivers    */
  45.             gotEvent = GetNextEvent(evtMask, event);
  46.             }
  47.  
  48.         if (!gotEvent)
  49.             {
  50.             if (event->what == nullEvent)
  51.                 {
  52.                 integer junk;
  53.                 IsDialogEvent(event);           /* flick TE's in dialogs    */
  54.                 DoIdles(&junk);                     /* run the idle procedures    */
  55.                 }
  56.             }
  57.         }
  58.     while (!gotEvent);
  59. }
  60.  
  61. integer MainEvents(integer evtMask)
  62. {
  63.     integer        part, junk;
  64.     WindowPtr    window;
  65.     EventRecord    event;
  66.  
  67.     WaitForEvent(evtMask, &event);
  68.  
  69.     if ( (event.what == keyDown) && (event.modifiers & cmdKey) )
  70.         {
  71.         if ( (event.message & 0x7F) == '.' )
  72.             stopped = TRUE;
  73.         else
  74.             {
  75.             }
  76.         return TRUE;
  77.         }
  78.  
  79.     if ( IsDialogEvent(&event) )
  80.         {
  81.         if ( HandleDEvent(&event) )
  82.             return FALSE;
  83.         }
  84.  
  85.     switch (event.what)
  86.         {
  87.         case mouseDown :
  88.             switch(part = FindWindow(event.where, &window))
  89.                 {
  90.                 case inMenuBar :
  91.                     break;
  92.                 case inSysWindow :
  93.                     SystemClick(&event, window);
  94.                     break;
  95.                 case inDrag :
  96.                 case inGrow :
  97.                 case inGoAway :
  98.                 case inContent :
  99.                 case inZoomIn :
  100.                 case inZoomOut :
  101.                     break;
  102.                 }
  103.             break;
  104.         case keyDown:
  105.         case autoKey:
  106.             break;
  107.         case activateEvt :
  108.             break;
  109.         case updateEvt :
  110.             break;
  111.         case osEvt:
  112.             switch ((event.message >> 24) & 0xFF)    /* high byte of message */
  113.                 {
  114.                 case mouseMovedMessage:
  115.                     CursorAdjust(event.where, cursRgn);      /* update cursor    */
  116.                     DoIdles(&junk);
  117.                     break;
  118.                 case suspendResumeMessage:
  119.                     inBackground = ((event.message & resumeFlag) == 0);
  120.                     break;
  121.                 default:
  122.                     break;
  123.                 }
  124.             break;
  125.         default :
  126.             break;
  127.         }
  128.  
  129.     return FALSE;
  130. }
  131.  
  132.  
  133. void Exit()
  134. {
  135.     ExitTCPS();
  136.  
  137.     ExitToShell();
  138. }
  139.  
  140. void CursorAdjust(Point where, RgnHandle crsRgn)
  141. {
  142. }
  143.  
  144.  
  145. void DoIdles(integer *state)
  146. {
  147.     EventRecord    event;
  148.  
  149.     RunBackground();
  150.     SystemTask();                                 /* run drivers    */
  151.     if ( EventAvail(everyEvent, &event) )
  152.         MainEvents(everyEvent);
  153.     if (stopped && *state > 0) *state = -1;
  154.  
  155. }
  156.  
  157. stdWinHand IsAppWindow(WindowPtr window)
  158. {
  159.     integer windowKind;
  160.     stdWinHand    sHand;
  161.  
  162.     if ( !window ) return NIL;
  163.  
  164.     /* check that the window is in our applications Zone */
  165.     if ( PtrZone((Ptr)window) != ApplicZone() )
  166.         return NIL;        /* not in our zone so not one of ours */
  167.  
  168.     windowKind = ((WindowPeek)window)->windowKind;
  169.     if ( windowKind < 8 && windowKind != 2 )
  170.         return NIL;
  171.  
  172.     sHand = (stdWinHand)StripAddress((Ptr)GetWRefCon(window));
  173.  
  174.     /* check that the refCon is in our applications Zone, if *
  175.      * the window is this should be too, but you never know     */
  176.     if ( HandleZone((Handle)sHand) != ApplicZone() )
  177.         return NIL;        /* something screwey here! */
  178.  
  179.     return sHand;
  180. }
  181.  
  182.  
  183. Boolean IsDAWindow(WindowPtr window)
  184. {
  185.     integer windowKind;
  186.  
  187.     if ( !window ) return FALSE;
  188.  
  189.     windowKind = ((WindowPeek)window)->windowKind;
  190.     if ( windowKind < 0 )
  191.         return TRUE;
  192.  
  193.     return FALSE;
  194. }
  195.  
  196.  
  197. LongWord GetSleep()
  198. {
  199.     if ( !inBackground )
  200.         {
  201.         if ( IsAppWindow(FrontWindow()) )
  202.             return (LongInt)GetCaretTime();
  203.         else
  204.             return 0x3FF;
  205.         }
  206.  
  207.     return 0x7FFFFFFFL;    /* if we are in the backgound we can sleep forever */
  208. }
  209.  
  210.  
  211. /* Returns the update region in local coordinates */
  212. void GetLocalUpdateRgn(WindowPtr window, RgnHandle localRgn)
  213. {
  214.     CopyRgn(((WindowPeek) window)->updateRgn, localRgn);    /* save old update region */
  215.     OffsetRgn(localRgn, window->portBits.bounds.left, window->portBits.bounds.top);
  216. } /* GetLocalUpdateRgn */
  217.  
  218.  
  219. /************************************************************************
  220.  ************************************************************************/
  221. Boolean noMenus = FALSE;
  222. void WaitForState(integer *state);
  223. void WaitForState(integer *state)
  224. {
  225.     extern Boolean Quitable;
  226.     Boolean quit_back = Quitable;
  227.     Quitable = FALSE;
  228.     noMenus = TRUE;
  229.     while (*state)
  230.         {
  231.         MainEvents(everyEvent);
  232.         RunBackground();
  233.         }
  234.     noMenus = FALSE;
  235. }
  236.